package com.cy.generic;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

/**
 * @DATE: 2021/3/15 11:37
 * @Author: LuckyH
 */

public class TestGeneric {
    static class Container<E>{
        void add(E e){
            System.out.println(e);
        }
    }

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        ArrayList<String> list = new ArrayList<String>();
        list.add("1");
        list.add("hello");

        //list.add(1);

        Class<? extends ArrayList> aClass = list.getClass();
        Method add = aClass.getMethod("add", Object.class);
        // 调用list的add方法

        add.invoke(list, 10);

        System.out.println(list);

        for (Object s : list) {
            String name = s.getClass().getName();
            System.out.println(name);
        }

        new Container<String>().add("1");







    }
}
